﻿Public Class BeachesList
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        myHeading.InnerHtml = "List of Beaches"
    End Sub

    Protected Sub OnRowCreated(sender As Object, e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#e2e2e2'")
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
        End If
    End Sub

    Protected Sub btn_findByName_Click(sender As Object, e As EventArgs) Handles btn_findByName.Click
        searchDatabase("BeachName", tb_search.Text)
    End Sub

    Protected Sub btn_findByRegion_Click(sender As Object, e As EventArgs) Handles btn_findByRegion.Click
        searchDatabase("Region", tb_search.Text)
    End Sub

    Private Function searchDatabase(ByVal buttonStr As String, ByVal searchStr As String)
        SqlDataSource1.SelectCommand = "SELECT * FROM BeachesDatabase WHERE " & buttonStr & " LIKE '%" & searchStr & "%'"
        SqlDataSource1.DataBind()
        Return True
    End Function

    Protected Sub SqlDataSource1_Selected(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Selected
        If (e.AffectedRows < 1) Then
            myHeading.InnerHtml = "No Beach found"
        End If
    End Sub
End Class